Skip to content

Comments

fix: escape SQL LIKE wildcards in database helper search functions#210

Open
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/database-search-wildcard-escaping
Open

fix: escape SQL LIKE wildcards in database helper search functions#210
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/database-search-wildcard-escaping

Conversation

@haosenwang1018
Copy link
Contributor

Summary

  • episodicSearch, semanticSearch, and proceduralSearch in src/state/database.ts interpolate the query string directly into SQL LIKE patterns (%${query}%) without escaping %, _, or \ characters
  • A query containing % (e.g. "100%") matches every row; a query containing _ (e.g. "file_name") matches unintended rows where _ acts as a single-character wildcard
  • This is the same class of bug previously fixed in the memory manager classes (EpisodicMemoryManager, SemanticMemoryManager, ProceduralMemoryManager), but the database-level helper functions were missed

Changes

  • Escape %, _, and \ in the query before interpolating into LIKE patterns
  • Add ESCAPE '\' clause to all affected LIKE expressions
  • Three functions fixed: episodicSearch (line 1403), semanticSearch (line 1470), proceduralSearch (line 1529)

Test plan

  • Added 7 new tests in database-search-wildcard.test.ts covering % and _ escaping for all three search functions
  • Tests verify that % in queries does not match all rows
  • Tests verify that _ in queries does not act as single-char wildcard
  • Full test suite passes (1009 tests)
  • TypeScript compilation passes (tsc --noEmit)

The database-level search helpers (episodicSearch, semanticSearch,
proceduralSearch) interpolate the query string directly into LIKE
patterns without escaping % and _ characters. A query containing
these characters alters the pattern semantics: "100%" matches every
row, and "file_name" matches "fileBname".

Escape %, _, and \ before interpolation and add ESCAPE '\' to each
LIKE clause, consistent with the fix already applied to the memory
manager classes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant